package com.baidu.model;

import java.util.List;

import com.jfinal.plugin.activerecord.Model;

/**
 * 百度账户
 * @author libs
 * 2015年7月20日11:28:30
 */
public class BDUser extends Model<BDUser>{
	
	private static final long serialVersionUID = 282908528936842633L;
	public static final BDUser dao = new BDUser();
	
	/**
	 * 查询用户绑定的百度账号列表
	 * @param userId
	 * @return
	 */
	public List<BDUser> findByUserId(String userId) {
		StringBuffer sql = new StringBuffer();
		sql.append("select a.* from bd_user a where a.isDeleted=0 and a.userGuid = ?");
		return BDUser.dao.find(sql.toString(), userId);
	}
	
	/**
	 * 根据用户和name查询用户是否已经绑定了用户
	 * @param userGuid
	 * @param name
	 * @return
	 */
	public BDUser findByUserAndBduss(String userGuid, String name) {
		StringBuffer sql = new StringBuffer();
		sql.append("select a.* from bd_user a where a.isDeleted=0 and a.userGuid = ? and a.nickName=?");
		return BDUser.dao.findFirst(sql.toString(), userGuid, name);
	}
	
	/**
	 * 查询所有百度账号
	 * @return
	 */
	public List<BDUser> findAll() {
		StringBuffer sql = new StringBuffer();
		sql.append("select * from bd_user where isDeleted=0");
		return find(sql.toString());
	}	
	
}
